package com.qyhl.module_practice.volunteer.newlist.newvol;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.flyco.tablayout.SlidingTabLayout;
import com.qyhl.module_practice.R;
import com.qyhl.module_practice.R2;
import com.qyhl.module_practice.volunteer.newlist.newvol.fragment.PracticeVolunteerNewFragment;
import com.qyhl.webtv.basiclib.base.BaseFragment;
import com.qyhl.webtv.commonlib.constant.ARouterPathConstant;
import com.qyhl.webtv.commonlib.utils.router.RouterManager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class PracticeNewVolunteerListFragment extends BaseFragment {
    @BindView(R2.id.tabLayout)
    SlidingTabLayout tabLayout;
    @BindView(R2.id.viewPager)
    ViewPager viewPager;

    private View view;

    public static PracticeNewVolunteerListFragment newInstance() {
        return new PracticeNewVolunteerListFragment();
    }


    @Override
    public void initImmersionBar() {
    }

    /**
     * 加载数据
     */
    private void loadData() {
        //下拉刷新
        initView();

    }


    @Override
    protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return view = inflater.inflate(R.layout.practice_fragment_volunteer_list_new, null);
    }

    @Override
    protected void create() {
        loadData();
    }

    @Override
    protected void setListener() {
    }

    @Override
    protected void onFirstVisible() {

    }

    @Override
    protected void onVisible() {

    }

    @Override
    protected void onHide() {

    }

    private void initView() {
        List<String> nameList = new ArrayList<>();
        List<Fragment> fragmentList = new ArrayList<>();
        nameList.add("项目排序");
        nameList.add("时间排序");
        nameList.add("积分排序");

        fragmentList.add(PracticeVolunteerNewFragment.newInstance(0));
        fragmentList.add(PracticeVolunteerNewFragment.newInstance(1));
        fragmentList.add(PracticeVolunteerNewFragment.newInstance(2));
        viewPager.setAdapter(new Adapter(getChildFragmentManager(), fragmentList, nameList));
        tabLayout.setViewPager(viewPager);
    }

    private void setListener2() {

    }


    @OnClick(R2.id.search_btn)
    public void onViewClicked() {
        RouterManager.router(ARouterPathConstant.PRACTICE_VOL_SEARCH);

    }

    class Adapter extends FragmentPagerAdapter {
        private List<Fragment> fragmentList;
        private List<String> names;

        Adapter(FragmentManager fm, List<Fragment> fragmentList, List<String> names) {
            super(fm);
            this.fragmentList = fragmentList;
            this.names = names;
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentList.get(position);
        }

        @Override
        public int getCount() {
            return fragmentList.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return names.get(position);
        }
    }

}
